package view.bookAdmiView;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import dao.BookDao;
import dao.BorrowImfDao;
import model.Book;
import model.BorrowImf;
import util.DbUtil;
import util.StringUtil;
import view.logOnView.LogOnFrm1;

import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.ImageIcon;
import java.awt.Color;

public class BookReturnInterFrm extends JInternalFrame {
	private JTextField s_userNameTxt;
	private JTextField s_passWordTxt;
	private JTextField s_bookIdTxt;
	private JTextField s_bookNameTxt;
	private JTable borrowImfTable;
	private JTextField idTxt;
	private JTextField userNameTxt;
	private JTextField passWordTxt;
	private JTextField bookNameTxt;
	private JTextField bookIdTxt;
	private JTextField borrowTimeTxt;
	private JTextField returnTimeTxt;
	private JTextField renewNumTxt;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JRadioButton notBorrowedJrb;
	private JRadioButton borrowedJrb;

	
	
	private DbUtil dbUtil=new DbUtil();
	private BorrowImfDao borrowImfDao=new BorrowImfDao();
	private BookDao bookDao=new BookDao();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BookReturnInterFrm frame = new BookReturnInterFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BookReturnInterFrm() {
		setBackground(new Color(224, 255, 255));
		getContentPane().setBackground(new Color(224, 255, 255));
		setTitle("图书归还");
		setIconifiable(true);
		setClosable(true);
		setBounds(100, 100, 1552, 862);
		
		JPanel borrowImfSearchPanel = new JPanel();
		borrowImfSearchPanel.setBackground(new Color(255, 218, 185));
		borrowImfSearchPanel.setBorder(new TitledBorder(null, "\u501F\u9605\u4FE1\u606F\u67E5\u8BE2", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JPanel bookBorrowImfPanel = new JPanel();
		bookBorrowImfPanel.setBackground(new Color(255, 218, 185));
		bookBorrowImfPanel.setBorder(new TitledBorder(null, "\u501F\u9605\u4FE1\u606F\u8868\u683C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JScrollPane bookBorrwImfScrollPane = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addComponent(bookBorrowImfPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(borrowImfSearchPanel, GroupLayout.DEFAULT_SIZE, 733, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED, 90, Short.MAX_VALUE)
					.addComponent(bookBorrwImfScrollPane, GroupLayout.PREFERRED_SIZE, 685, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(53)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(bookBorrwImfScrollPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 760, Short.MAX_VALUE)
						.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
							.addComponent(borrowImfSearchPanel, GroupLayout.PREFERRED_SIZE, 231, GroupLayout.PREFERRED_SIZE)
							.addGap(30)
							.addComponent(bookBorrowImfPanel, GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)))
					.addContainerGap())
		);
		
		JLabel id = new JLabel("编   号：");
		id.setFont(new Font("宋体", Font.BOLD, 25));
		
		JLabel userName = new JLabel("用 户 名：");
		userName.setFont(new Font("宋体", Font.BOLD, 25));
		
		idTxt = new JTextField();
		idTxt.setFont(new Font("宋体", Font.BOLD, 25));
		idTxt.setColumns(10);
		
		userNameTxt = new JTextField();
		userNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		userNameTxt.setColumns(10);
		
		JLabel passWord = new JLabel("用户密码：");
		passWord.setFont(new Font("宋体", Font.BOLD, 25));
		
		passWordTxt = new JTextField();
		passWordTxt.setFont(new Font("宋体", Font.BOLD, 25));
		passWordTxt.setColumns(10);
		
		JLabel bookName = new JLabel("图书名称：");
		bookName.setFont(new Font("宋体", Font.BOLD, 25));
		
		bookNameTxt = new JTextField();
		bookNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		bookNameTxt.setColumns(10);
		
		JLabel bookId = new JLabel("图书编号：");
		bookId.setFont(new Font("宋体", Font.BOLD, 25));
		
		bookIdTxt = new JTextField();
		bookIdTxt.setFont(new Font("宋体", Font.BOLD, 25));
		bookIdTxt.setColumns(10);
		
		JLabel status = new JLabel("图书状态：");
		status.setFont(new Font("宋体", Font.BOLD, 25));
		
		JLabel borrowTime = new JLabel("借阅日期：");
		borrowTime.setFont(new Font("宋体", Font.BOLD, 25));
		
		borrowTimeTxt = new JTextField();
		borrowTimeTxt.setFont(new Font("宋体", Font.BOLD, 25));
		borrowTimeTxt.setColumns(10);
		
		JLabel returnTime = new JLabel("还书日期：");
		returnTime.setFont(new Font("宋体", Font.BOLD, 25));
		
		returnTimeTxt = new JTextField();
		returnTimeTxt.setFont(new Font("宋体", Font.BOLD, 25));
		returnTimeTxt.setColumns(10);
		
		JLabel renewNum = new JLabel("续借次数：");
		renewNum.setFont(new Font("宋体", Font.BOLD, 25));
		
		renewNumTxt = new JTextField();
		renewNumTxt.setFont(new Font("宋体", Font.BOLD, 25));
		renewNumTxt.setColumns(10);
		
		JButton returnButton = new JButton("还书");
		returnButton.setIcon(new ImageIcon(BookReturnInterFrm.class.getResource("/images/bookAdmi/还书按钮.png")));
		returnButton.setFont(new Font("宋体", Font.BOLD, 25));
		returnButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				bookRetrunActionPerformed(e);
			}
		});
		
		JButton cancelButton_1 = new JButton("取消");
		cancelButton_1.setFont(new Font("宋体", Font.BOLD, 25));
		cancelButton_1.setIcon(new ImageIcon(BookReturnInterFrm.class.getResource("/images/bookAdmi/重置.png")));
		cancelButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				reTurnResetActionPerform(e);
			}
		});
		
		notBorrowedJrb = new JRadioButton("在馆");
		notBorrowedJrb.setBackground(new Color(255, 218, 185));
		notBorrowedJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup.add(notBorrowedJrb);
		
		borrowedJrb = new JRadioButton("已借");
		borrowedJrb.setBackground(new Color(255, 218, 185));
		borrowedJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup.add(borrowedJrb);
		borrowedJrb.setSelected(true);
		GroupLayout gl_bookBorrowImfPanel = new GroupLayout(bookBorrowImfPanel);
		gl_bookBorrowImfPanel.setHorizontalGroup(
			gl_bookBorrowImfPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
							.addComponent(bookId)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(bookIdTxt, GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
						.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
							.addComponent(id)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
							.addComponent(passWord)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(passWordTxt, GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
						.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.TRAILING)
							.addGroup(Alignment.LEADING, gl_bookBorrowImfPanel.createSequentialGroup()
								.addComponent(borrowTime)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(borrowTimeTxt, GroupLayout.PREFERRED_SIZE, 171, GroupLayout.PREFERRED_SIZE))
							.addGroup(Alignment.LEADING, gl_bookBorrowImfPanel.createSequentialGroup()
								.addComponent(renewNum)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.LEADING)
									.addComponent(returnButton)
									.addComponent(renewNumTxt)))))
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
							.addGap(100)
							.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(userName)
								.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.TRAILING)
									.addComponent(status)
									.addComponent(bookName)
									.addComponent(returnTime)))
							.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
									.addGap(8)
									.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.TRAILING, false)
										.addGroup(Alignment.LEADING, gl_bookBorrowImfPanel.createSequentialGroup()
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(bookNameTxt))
										.addComponent(userNameTxt, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 159, GroupLayout.PREFERRED_SIZE)))
								.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(returnTimeTxt, GroupLayout.PREFERRED_SIZE, 151, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(notBorrowedJrb)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(borrowedJrb))))
						.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
							.addGap(14)
							.addComponent(cancelButton_1)))
					.addContainerGap())
		);
		gl_bookBorrowImfPanel.setVerticalGroup(
			gl_bookBorrowImfPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_bookBorrowImfPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(id)
						.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
						.addComponent(userName)
						.addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
					.addGap(35)
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(passWord)
						.addComponent(passWordTxt, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
						.addComponent(bookName)
						.addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
					.addGap(44)
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(bookId)
						.addComponent(bookIdTxt, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
						.addComponent(status)
						.addComponent(notBorrowedJrb)
						.addComponent(borrowedJrb))
					.addGap(34)
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(borrowTime)
						.addComponent(borrowTimeTxt, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
						.addComponent(returnTime)
						.addComponent(returnTimeTxt, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
					.addGap(49)
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(renewNum)
						.addComponent(renewNumTxt, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
					.addGap(48)
					.addGroup(gl_bookBorrowImfPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(returnButton)
						.addComponent(cancelButton_1))
					.addContainerGap(48, Short.MAX_VALUE))
		);
		bookBorrowImfPanel.setLayout(gl_bookBorrowImfPanel);
		
		borrowImfTable = new JTable();
		
		borrowImfTable.setBackground(new Color(250, 235, 215));//设置表格背景颜色
		borrowImfTable.getTableHeader().setFont(new Font("微软雅黑",Font.BOLD,20));//设置表格开头字体
		borrowImfTable.getTableHeader().setBackground(new Color(127, 255, 212));//设置表格开头背景颜色
		borrowImfTable.setFont(new Font("楷体", Font.BOLD, 22));//设置表格内容字体
		borrowImfTable.setForeground(new Color(0,0,0));//设置表格内容字体颜色		
		borrowImfTable.setRowHeight(borrowImfTable.getRowHeight()+20);//设置表格内容的行高
		
		borrowImfTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent met) {
				borrowImfTableMousePressed(met);
				
			}
		});
		borrowImfTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "\u7528\u6237\u540D", "\u7528\u6237\u5BC6\u7801", "\u56FE\u4E66\u540D\u79F0", "\u56FE\u4E66\u7F16\u53F7", "\u56FE\u4E66\u72B6\u6001", "\u501F\u9605\u65E5\u671F", "\u8FD8\u4E66\u65E5\u671F", "\u7EED\u501F\u6B21\u6570"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, false, false, false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		bookBorrwImfScrollPane.setViewportView(borrowImfTable);
		
		JLabel s_userName = new JLabel("用户名：");
		s_userName.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_userNameTxt = new JTextField();
		s_userNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_userNameTxt.setColumns(10);
		
		JLabel s_passWord = new JLabel("密码：");
		s_passWord.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_passWordTxt = new JTextField();
		s_passWordTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_passWordTxt.setColumns(10);
		
		JLabel s_bookId = new JLabel("图书编号：");
		s_bookId.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_bookIdTxt = new JTextField();
		s_bookIdTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_bookIdTxt.setColumns(10);
		
		JLabel s_bookName = new JLabel("图书名称：");
		s_bookName.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_bookNameTxt = new JTextField();
		s_bookNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_bookNameTxt.setColumns(10);
		
		JButton searchButton = new JButton("查询");
		searchButton.setIcon(new ImageIcon(BookReturnInterFrm.class.getResource("/images/bookAdmi/查询.png")));
		searchButton.setFont(new Font("宋体", Font.BOLD, 25));
		searchButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				borrowImfSearchActionPerformed(e);
			}
		});
		
		JButton cancelButton = new JButton("取消");
		cancelButton.setFont(new Font("宋体", Font.BOLD, 25));
		cancelButton.setIcon(new ImageIcon(BookReturnInterFrm.class.getResource("/images/bookAdmi/重置.png")));
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				searchReSetActionperFormed(e);
			}
		});
		GroupLayout gl_borrowImfSearchPanel = new GroupLayout(borrowImfSearchPanel);
		gl_borrowImfSearchPanel.setHorizontalGroup(
			gl_borrowImfSearchPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_borrowImfSearchPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_borrowImfSearchPanel.createSequentialGroup()
							.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(s_userName)
								.addComponent(s_bookId))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(s_bookIdTxt, GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
								.addComponent(s_userNameTxt, GroupLayout.PREFERRED_SIZE, 174, GroupLayout.PREFERRED_SIZE))
							.addGap(79))
						.addGroup(gl_borrowImfSearchPanel.createSequentialGroup()
							.addComponent(searchButton)
							.addGap(136)))
					.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_borrowImfSearchPanel.createSequentialGroup()
							.addComponent(s_passWord)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(s_passWordTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_borrowImfSearchPanel.createSequentialGroup()
							.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.TRAILING)
								.addComponent(cancelButton)
								.addComponent(s_bookName))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(s_bookNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addGap(28))
		);
		gl_borrowImfSearchPanel.setVerticalGroup(
			gl_borrowImfSearchPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_borrowImfSearchPanel.createSequentialGroup()
					.addGap(29)
					.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(s_userName)
						.addComponent(s_userNameTxt, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(s_passWord)
						.addComponent(s_passWordTxt, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE))
					.addGap(33)
					.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(s_bookId)
						.addComponent(s_bookIdTxt, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
						.addComponent(s_bookName)
						.addComponent(s_bookNameTxt, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
					.addGap(22)
					.addGroup(gl_borrowImfSearchPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(cancelButton)
						.addComponent(searchButton))
					.addContainerGap())
		);
		borrowImfSearchPanel.setLayout(gl_borrowImfSearchPanel);
		getContentPane().setLayout(groupLayout);
		
		//设置JFrame居中显示
		this.setLocation(160, 5);
		this.fillTable(new BorrowImf());
	}

	
	/**
	 * 还书事件处理
	 * @param e
	 */
	private void bookRetrunActionPerformed(ActionEvent evt) {
		if(StringUtil.isEmpty(this.idTxt.getText())) {
			JOptionPane.showMessageDialog(null, "请选择需要归还的书籍！");
		}
		else{
			int id=Integer.parseInt(this.idTxt.getText());
			String userName=this.userNameTxt.getText();
			String passWord=this.passWordTxt.getText();
			int bookId=Integer.parseInt(this.bookIdTxt.getText());
			String bookName=this.bookNameTxt.getText();		
			int renewNum=Integer.parseInt(this.renewNumTxt.getText());
			String status="";
			if(notBorrowedJrb.isSelected()) {
				status="在馆";
				
			}
			else if(borrowedJrb.isSelected()) {
				status="已借";
			}
			
			String borrowTime2=this.borrowTimeTxt.getText();
			java.sql.Date borrowTime=java.sql.Date.valueOf(borrowTime2);
			
			String returnTime2=this.returnTimeTxt.getText();
			java.sql.Date returnTime=java.sql.Date.valueOf(returnTime2);
			
			BorrowImf borrowImf=new BorrowImf(id,userName,bookName,borrowTime,returnTime,renewNum,bookId,status, passWord);
			Book book =new Book(bookId,bookName,status);
			
			Connection con=null;
			try {
				con=dbUtil.getCon();
				int addNum=borrowImfDao.update(con, borrowImf);			
				if(addNum==1 ) {				
					if(StringUtil.compareDate(returnTime2)) {
						JOptionPane.showMessageDialog(null, "该书已超过规定借阅时间还未归还，请按规定支付罚款金额后归还图书");
						int result=JOptionPane.showConfirmDialog(null, "是否已经缴纳罚款");
						if(result==0) {
							JOptionPane.showMessageDialog(null, "图书归还成功!");
							bookDao.update2(con,book);//将借阅图书状态更新为已借
							this.reSetValue();
							this.fillTable(new BorrowImf());
						}			
					}
					else {
						JOptionPane.showMessageDialog(null, "图书归还成功!");
						bookDao.update2(con,book);//将借阅图书状态更新为已借
						this.reSetValue();
						this.fillTable(new BorrowImf());
						
					}
					
					
				}
				else {
					JOptionPane.showMessageDialog(null, "图书归还失败");
				}
			}catch(Exception e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(null, "图书归还失败");
			}finally {
				try {
					dbUtil.closeCon(con);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
		
	}

	/**
	 * 取消还书表格事件处理
	 * @param e
	 */
	private void reTurnResetActionPerform(ActionEvent e) {
		this.reSetValue();
	}
	
	private void reSetValue() {
		this.idTxt.setText("");
		this.userNameTxt.setText("");
		this.passWordTxt.setText("");
		this.bookIdTxt.setText("");
		this.bookNameTxt.setText("");
		this.borrowTimeTxt.setText("");
		this.returnTimeTxt.setText("");
		this.renewNumTxt.setText("");
		this.borrowedJrb.setSelected(true);
		
	}
	/**
	 * 取消借阅信息查询事件处理
	 * @param e
	 */
	private void searchReSetActionperFormed(ActionEvent e) {
		this.s_bookIdTxt.setText("");
		this.s_bookNameTxt.setText("");
		this.s_passWordTxt.setText("");
		this.s_userNameTxt.setText("");
		
	}

	/**
	 * 表单点击事件处理
	 * @param met
	 */
	private void borrowImfTableMousePressed(MouseEvent met) {
		
		int row=this.borrowImfTable.getSelectedRow();
		String status=(String)borrowImfTable.getValueAt(row, 5);
		if(status.equalsIgnoreCase("在馆")) {
			JOptionPane.showMessageDialog(null, "该书已经归还在馆，请选择正确图书！");
			this.reSetValue();
		}
		else {
			this.idTxt.setText((String)borrowImfTable.getValueAt(row, 0));
			this.userNameTxt.setText((String)borrowImfTable.getValueAt(row, 1));
			this.passWordTxt.setText((String)borrowImfTable.getValueAt(row, 2));
			this.bookNameTxt.setText((String)borrowImfTable.getValueAt(row, 3));
			this.bookIdTxt.setText((String)borrowImfTable.getValueAt(row, 4));
			
			if("在馆".equals(status)) {
				this.notBorrowedJrb.setSelected(true);
			}else if("已借".equals(status)) {
				this.borrowedJrb.setSelected(true);
			}	
			this.borrowTimeTxt.setText((String)borrowImfTable.getValueAt(row, 6));
			this.returnTimeTxt.setText((String)borrowImfTable.getValueAt(row, 7));
			this.renewNumTxt.setText((String)borrowImfTable.getValueAt(row, 8));
			
			
		}
		
	}

	/**
	 * 借阅信息查询事件处理
	 * @param e
	 */
	private void borrowImfSearchActionPerformed(ActionEvent e) {
		String userName=this.s_userNameTxt.getText();
		String passWord=this.s_passWordTxt.getText();
		
		String bookName=this.s_bookNameTxt.getText();
		if(StringUtil.isEmpty(this.s_bookIdTxt.getText())) {
			JOptionPane.showMessageDialog(null, "请输入图书编号");
		}else {
			int bookId=Integer.parseInt(this.s_bookIdTxt.getText());
			BorrowImf borrowImf=new BorrowImf(userName,bookName,bookId,passWord);
			this.fillTable(borrowImf);
		}
		
		
	}
	
	
	/**
	 * 初始化表格数据
	 * @param borrowImf
	 */
	private void fillTable(BorrowImf borrowImf) {
		DefaultTableModel dtm=(DefaultTableModel)borrowImfTable.getModel();
		dtm.setRowCount(0);
		Connection con=null;
		try {
			con=dbUtil.getCon();
			ResultSet rs=borrowImfDao.list(con, borrowImf);
			while(rs.next()) {
				Vector v=new Vector();
				v.add(rs.getString("id"));
				v.add(rs.getString("b_userName"));
				v.add(rs.getString("b_passWord"));
				v.add(rs.getString("b_bookName"));
				v.add(rs.getString("bookId"));
				v.add(rs.getString("b_status"));
				v.add(rs.getString("borrowTime"));
				v.add(rs.getString("returnTime"));
				v.add(rs.getString("renewNum"));
				dtm.addRow(v);
			}
					
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
		
	
	}	
	
}
